import React from 'react'
import Controls from '@views/testing-center/js/controls'
// ===================================================================== antd
import { Dropdown } from 'antd'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy 
const Button = $Lazy.load(()=>import('@antd/button'))
// ===================================================================== 弹窗
const PatientDetailModal 		= $Lazy.state(()=>import('@views/_public/patient-detail-modal'), 1)
const ReasonModal 				= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/reason-modal'), 1)
const WaibaolModal 				= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/waibao-modal'))
const ControlLogModal 			= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/control-log-modal'), 1)
const SetResultModal 			= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/set-result-modal'), 1)
const NoPassModal 				= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/no-pass-modal'), 1)
const HandAuditModal 			= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/hand-audit-modal'), 1)
const MergeProjectModal 		= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/merge-project-modal'), 1)
const UploadResultModalModal	= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/upload-result-modal'), 1)
const StatisticsModal 			= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/statistics-modal'), 1)
const StopReportModal 			= $Lazy.state(()=>import('#private/pages/stop-report-modal'), 1)
const CheckSameNameModal 		= $Lazy.state(()=>import('@views/_public/preview-audit-report/cpt/history-modal'), 1)
const GroupWaibaolModal 		= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/group-waibao-modal'), 1)
const ModSpecTypeModal 			= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/modSpecType-modal'), 1)
const SuperSearchModal 			= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/superSearch-modal'), 1)
const CreateBoardModal 			= $Lazy.state(()=>import('@views/testing-center/js/controls/modal/create-board-modal'), 1)
// ===================================================================== 
class Index extends React.Component{
	state = { 
		index:0,
		selectedKeys:[],
		selectedRows:[],
		constrol:[],
		info:{},
	}
	rowsType = 1		// 区分是左边表格(值为1)还是右边表格(值为2)	2021-9-9  --马婷
	componentDidMount(){
		const { result_model, BingLiMode, index  } = this.props.top
		// 权限配置
		// if( index !== -1 ){
		// 	const _index = oldTabs.findIndex( v => +v.status === +tabs[index].status )
		// 	this.change( _index )
		// 	this.isBingLiMode = BingLiMode.includes(result_model)
		// }
		this.change( index )
		this.isBingLiMode = BingLiMode.includes(result_model)
	}
	componentWillUnmount(){
		this.setState = () => false
	}
	
	setKeys = rows => {
		this.rows = rows
		this.info = rows.info
		this.setState({ constrol: Controls.call(this, this.rows)[this.index] })
	}
	
	getInfo = info => {
		this.info = info
		this.setState({ constrol: Controls.call(this, this.rows)[this.index] })
	}
	
	change = index => {
		const { result_model, isEntrust  } = this.props.top
		this.index = index
		this.info = {}
		this.setState({ constrol: Controls.call(this, { mode: result_model, isEntrust})[index]  })
	}
	
	clear = () => this.props.searchRef().clear()
	
	onRefresh = param => this.props.searchRef().onRefresh({...param, rowsType: this.rowsType})
	onSearch = param => this.props.searchRef().onSubmit(param)
	
	onRefreshInfo = () => { this.props.tableRef().onRefreshInfo() }
	// 获取完整项目参数
	cross_page_submit = 0
	getCrossPageSubmit = cross_page_submit => { this.cross_page_submit = cross_page_submit }
	
	// 是否使用上次报告时间 2021-9-2 11:21:41 ?F10: PM? --伍智睿
	use_old_approve_at = 0
	useOldApproveAt = use_old_approve_at => { this.use_old_approve_at = use_old_approve_at }
	
	render(){
		const { constrol } = this.state
		const { query } = this.props?.top
		return (
			<>
				{
					$fn.hasArray(constrol) && (
						<div className='xplr bcf'>
							<div style={{padding:'3px 0 0 0'}}>
								{/* 添加相关操作说明 20210927 耿琰 */}
								{
									constrol.map((v,i)=> {
										// 上机增加空结果上机 2021-9-28  --马婷 
										// $fn.hasObject(v) && <Button tipName={v.tipName} tip={v.tip} key={i} className='mr10' label={v.name} onClick={v.onClick} loading={v.loading} disabled={v.disabled} />
										let d
										if($fn.hasObject(v)) {
											if (v.type === 'select') {
												d = (<div className='mr5' key={i} style={{display: 'inline-block'}}>
														<Dropdown overlay={v.menu} placement="bottomLeft" arrow trigger={['click']}  >
															<Button tipName={v.tipName} tip={v.tip} label={'选择上机类型'} />
														</Dropdown>
													</div>)
											} else {
												d =	<Button danger={ ['删除结果'].includes(v.name) } tipName={v.tipName} tip={v.tip} key={i} className='mr10' label={v.name} onClick={v.onClick} loading={v.loading} disabled={v.disabled} />
											}
										}
										return d
									})
								}
							</div>
						</div>
					)
				}
				{/* 迟发、退单、项目中止 */}
				<ReasonModal onRef	= { ref => this.reasonModal = ref } onRefresh={ this.onRefresh } onClear = {this.clear} />
				{/* 修改资料 */}
				<PatientDetailModal onRef = { ref => this.patientDetailModal = ref } onRefresh={ ()=>{this.onRefresh();this.onRefreshInfo()} } />
				{/* 转外包 */}
				<WaibaolModal onRef = { ref => this.waibaolModal = ref } onRefresh={ this.onRefresh } onClear = {this.clear} way ={this.props.top.way} rowsType={this.rowsType} />
				{/* 结果操作日志 */}
				<ControlLogModal onRef = { ref => this.controlLogModal = ref } />
				{/* 设置结果 */}
				<SetResultModal onRef = { ref => this.setResultModal = ref } onRefresh={ this.onRefresh } />
				{/* 不通过 */}
				<NoPassModal onRef = { ref => this.noPassModal = ref } onRefresh={ this.onRefresh } onClear = {this.clear} isBingLiMode={this.isBingLiMode} rowsType={this.rowsType}/>
				{/* 手动批准 */}
				<HandAuditModal onRef = { ref => this.handAuditModal = ref } onRefresh={ this.onRefresh } onClear = {this.clear} />
				{/* 合并管理项目 */}
				<MergeProjectModal onRef = { ref => this.mergeProjectModal = ref }/>
				{/* 上传结束 */}
				<UploadResultModalModal onRef = { ref => this.uploadResultModalModal = ref } {...this.props}/>
				{/* 统计 */}
				<StatisticsModal onRef = { ref => this.statisticsModal = ref } />
				{/* 报告单终止 */}
				<StopReportModal onRef = { ref => this.stopReportModal = ref } api='ts-report-card/upstatusabnormal' onRefresh={ this.onRefresh } onClear = {this.clear}/>
				{/* 查看同名 */}
				<CheckSameNameModal onRef = { ref => this.checkSameNameModal = ref } />
				{/* 集团内转外包 */}
				<GroupWaibaolModal onRef = { ref => this.groupWaibaoModal = ref } query={query} onRefresh={ this.onRefresh } onClear = {this.clear} />
				{/* 批量修改标本类型 */}
				<ModSpecTypeModal onRef = { ref => this.modSpecTypeModal = ref } onRefresh={ this.onRefresh } way ={this.props.top.way} rowsType={this.rowsType} />
				{/* 超级搜索 */}
				<SuperSearchModal onRef = { ref => this.superSearchModal = ref } onRefresh={ this.onRefresh } />
				{/* 生成布板  2022-7-27 --马婷 */}
				<CreateBoardModal onRef = { ref => this.createBoardModal = ref } onRefresh={ this.onRefresh } />
			</>
		)
	}
}

export default Index